package mqtt_connector

import (
	"github.com/google/uuid"
	"strings"
	"time"
)

type MqttClientProtocolInfo struct {
	UserName        string        //MQTT账号(留空默认网关编号)
	Password        string        //MQTT密码(留空默认网关密码)
	clientId        string        //ClientID(留空为随机ID)
	SubscribeTopic  string        //订阅主题
	PublicTopic     string        // 发布主题
	IsRetained      bool          //MQTT消息持久性(retained)
	EnableAnonymous bool          //是否匿名登录
	EnableBadQos    bool          //发送坏质量码的数据
	KeepAlive       time.Duration //链路保活时间
	//转发测点ID类型
	//0:测点名称 tag_name
	//1:测点地址 obj_addr
	//2: 物模标识 tag_desc
	TransferKey     int
	DeviceNameField string //设备名称字段
}

func (m *MqttClientProtocolInfo) PublicAddrAsDeviceName() bool {
	return m.DeviceNameField == "0"
}

func (m *MqttClientProtocolInfo) CommunicationAddrAsDeviceName() bool {
	return m.DeviceNameField == "1"
}

func (receiver *MqttClientProtocolInfo) ClientId() string {
	if strings.TrimSpace(receiver.clientId) == "" {
		receiver.clientId = uuid.New().String()
	}
	return receiver.clientId
}

func (receiver *MqttClientProtocolInfo) SetClientId(clientId string) {
	receiver.clientId = strings.TrimSpace(clientId)
	if receiver.clientId == "" {
		receiver.clientId = uuid.New().String()
	}
}
